package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.vo.FileResp;
import com.ruoyi.system.domain.vo.FileUploadReq;
import com.ruoyi.system.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-11-12  18:00
 */
@Api(tags = "OSS接口")
@RestController
@RequestMapping("/oss")
public class FileController {

    @Autowired
    private FileService fileService;

//    @ApiPermission(permissions = {PermissionConstant.FILE_UPLOAD})
    @ApiOperation("上传文件")
    @PostMapping("/upload")
    public AjaxResult upload(FileUploadReq req){
        FileResp resp = fileService.upload(req);
        AjaxResult res = new AjaxResult();
        res.put("data", resp.getDownloadUrl());
        return res;
    }


//    @ApiPermission(permissions = {PermissionConstant.FILE_DOWNLOAD})
    @ApiOperation("获取文件")
    @GetMapping("/download/{fileId}")
    public ResponseEntity<byte[]> download(@PathVariable("fileId") Long fileId){
        return fileService.download(fileId);
    }


}
